<template>
  <div id="add">
    <!-- 头部 -->
    <div class="navebar">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="人员编号">
          <el-input
            v-model="formInline.taskCode"
            placeholder="请输入"
            style="width: 200px"
          />
        </el-form-item>
        <el-form-item label="区域搜索">
          <el-select
            v-model="formInline.status"
            placeholder="请选择"
            style="width: 200px"
          >
            <el-option
              v-for="(item, index) in taskSty"
              :key="index"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit">
            查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="boxs">
      <div class="tabel bos">
        <el-table
          v-loading="loading"
          stripe
          tooltip-effect="dark"
          :data="SearchList"
          style="width: 100%"
          :header-cell-style="{
            //标题头部的颜色
            background: '#f5f7fa',
            height: '45px',
          }"
        >
          <el-table-column fixed type="index" label="序号" width="90" />
          <el-table-column prop="userName" label="人员名称" width="220" />
          <el-table-column prop="regionName" label="归属区域" width="230" />
          <el-table-column prop="vmRow" label="角色" width="230">
            <template slot-scope="scope">
              {{ role[scope.row.roleId] }}
            </template>
          </el-table-column>
          <el-table-column prop="mobile" label="联系电话" width="230" />
          <el-table-column fixed="right" label="操作" width="200">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="medium "
                @click="cargo(scope.row)"
              >查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 实现分页
        current-page 当前页数
        page-size 每页显示个数
        total 总条目数
        current-change 页面改变时会触发
        prev-text="上一页"
        next-text="下一页"
         -->
        <div class="block">
          <el-pagination
            background
            :current-page.sync="pageOption.pageIndex"
            :page-size="pageOption.pagesize"
            layout="total,  pager, prev, next"
            :total="total"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>

    <!-- 查看详情弹出框 -->
  </div>
</template>

<script>
import { getUserApi, serveList, getRegionListApi } from '@/api'
// import { Message } from 'element-ui'
export default {
  name: 'WordlosdList',
  data() {
    return {
      loading: false,
      deltacticsVisible: false,
      SearchList: [], // 表格
      currentPage1: 10,
      total: 0,
      imageUrl: '',
      taskSty: [], // 角色下拉
      regionNameList: [],
      // 搜索框
      formInline: {
        taskCode: ''
      },
      // 搜索传入的数值
      pageOption: {
        pageIndex: 1,
        pagesize: 10
      },
      // 售货机状态枚举
      vm: {
        0: '未投放',
        1: '运营',
        3: '撤机'
      },
      // 角色枚举
      role: {
        2: '运营员',
        3: '运维员'
      }
    }
  },
  created() {
    this.searchDevice()
  },
  methods: {
    // 封装页面初始化请求数据
    async searchDevice() {
      const { data } = await getUserApi(this.pageOption)
      console.log(data)
      this.SearchList = data.currentPageRecords
      this.total = +data.totalCount
      this.loading = false
    },
    // 封装弹窗打开请求的数据
    async  openCenterDialog() {
      const { data } = await serveList()
      this.roleIdList = data
      const res = await getRegionListApi({
        pageIndex: 1,
        pageSize: 100000
      })
      console.log(res)
      this.regionNameList = res.data.currentPageRecords
    },

    // 查询
    async onSubmit() {
      console.log('submit!')
      this.loading = true
      const { data } = await getUserApi({
        ...this.pageOption,
        userName: this.formInline.taskCode
      })
      this.SearchList = data.currentPageRecords
      this.total = +data.totalCount
      this.loading = false
    },

    // 弹窗打开执行的回调
    openFn() {
      this.openCenterDialog()
    },

    // 获取下拉框的label值
    selectChanged(id) {
      console.log(id)
      this.departForm.regionName = this.regionNameList.find(item => item.id === id).name
      console.log(this.departForm)
    },

    // 查看详情
    // 实现数据回显
    cargo(val) {
      console.log('修改')
      this.centerDialogVisible = true
      console.log(val)
      this.departForm = val
    },

    // 关闭弹窗
    closeFn() {
      this.centerDialogVisible = false
    },

    // 实现分页
    handleCurrentChange(val) {
      this.loading = true
      console.log(val)
      this.pageOption.pageIndex = val
      this.getDeviceList()
      this.loading = false
    }
  }
}
</script>

<style lang="scss" scoped>
#add {
  overflow: hidden;
  background-color: #f8fafd;
}
.navebar {
  margin: 20px 19px 0;
  padding-top: 14px;
  padding-left: 18px;
  height: 64px;
  background-color: #fff;
}
// 表格
.boxs {
  margin: 20px 19px 0;
  padding: 1px 0 1px 18px;
  background-color: #fff;
}
// 表格高度
.el-table .el-table__cell {
  padding: 3px 0 0 0;
}
// 内容
.el-descriptions {
  padding: 0px 0px 0px 30px;
}
.dils .el-dialog__footer {
  margin-top: -8px;
  padding: 10px 248px 20px;
}
.dils .el-dialog__body {
  padding: 30px 46px;
}
.dils .el-descriptions-item__label .has-colon {
  margin-right: 19px;
}
.dialog-footer {
  margin-top: 10px;
}
.btnquxiao {
  margin-right: 20px;
  height: 37px;
}
// 分页器
.block {
  margin: 20px 0;
}
.tabel {
  margin-top: 19px;
}
.btn-prev {
  margin-left: 100px;
}
</style>

